home *** CD-ROM | disk | FTP | other *** search
/ Software Explosion / Software Explosion (Fore-Matt Home Computing)(1996).iso / games / workbench / labyrinth_ii / talk.c < prev   
C/C++ Source or Header  |  1988-10-04  |  3KB  |  135 lines

  1.  
  2. /* Speech routines by Russell Wallace 1988, developed from speech demo program
  3.  * in ROM Kernel Manual. Routines are as follows:
  4.  * openmouth () sets everything up - returns nonzero if error condition
  5.  * say (string) says a null-terminated character string
  6.  * closemouth () shuts everything down - don't use it if openmouth ()
  7.  *    returned an error.
  8.  * Parameters for voice are contained in openmouth () and may be changed,
  9.  * so may MAXLEN if you have very long strings or all of them are going to
  10.  * be fairly short. Use +L if compiling with Aztec C. Requires presence of
  11.  * translator.library in system disk LIBS directory.
  12.  * This code may be freely used in writing Amiga programs. */
  13.  
  14. #include "exec/exec.h"
  15. #include "exec/execbase.h"
  16. #include "devices/narrator.h"
  17. #include "libraries/translator.h"
  18.  
  19. #define MAXLEN 1024        /* Maximum length of translated string */
  20.  
  21. struct MsgPort *readport=0;
  22. struct MsgPort *writeport=0;
  23.  
  24. struct MsgPort *CreatePort ();
  25. struct IORequest *CreateExtIO ();
  26. struct Library *OpenLibrary ();
  27.  
  28. struct narrator_rb *writeNarrator=0;
  29. struct mouth_rb *readNarrator=0;
  30. struct Library *TranslatorBase=0;
  31. UBYTE *sampleinput;
  32. UBYTE outputstring[MAXLEN];
  33. BYTE audChanMasks[4]={3,5,10,12};
  34.  
  35. int openmouth ()
  36. {
  37.     TranslatorBase=OpenLibrary ("translator.library",1);
  38.     if (TranslatorBase==0)
  39.         return (1);
  40.     writeport=CreatePort (0,0);
  41.     if (writeport==0)
  42.     {
  43.         closemouth ();
  44.         return (3);
  45.     }
  46.     readport=CreatePort (0,0);
  47.     if (readport==0)
  48.     {
  49.         closemouth ();
  50.         return (4);
  51.     }
  52.     writeNarrator=(struct narrator_rb *)CreateExtIO (writeport,sizeof(struct narrator_rb));
  53.     if (writeNarrator==0)
  54.     {
  55.         closemouth ();
  56.         return (5);
  57.     }
  58.     readNarrator=(struct mouth_rb *)CreateExtIO (readport,sizeof(struct mouth_rb));
  59.     if (readNarrator==0)
  60.     {
  61.         closemouth ();
  62.         return (6);
  63.     }
  64.  
  65.         /* Set up parameters for write-message to Narrator device */
  66.  
  67.     writeNarrator->ch_masks=(audChanMasks);
  68.     writeNarrator->nm_masks=sizeof(audChanMasks);
  69.     writeNarrator->message.io_Data=(APTR)outputstring;
  70.     writeNarrator->message.io_Length=strlen (outputstring);
  71.     writeNarrator->mouths=0;    /* Don't bother calculating mouths */
  72.     writeNarrator->message.io_Command=CMD_WRITE;
  73.  
  74.         /* Open device */
  75.  
  76.     if (OpenDevice ("narrator.device",0,writeNarrator,0))
  77.     {
  78.         closemouth ();
  79.         return (7);
  80.     }
  81.  
  82.         /* Set up parameters for read-message to Narrator device */
  83.  
  84.     readNarrator->voice.message.io_Device=writeNarrator->message.io_Device;
  85.     readNarrator->voice.message.io_Unit=writeNarrator->message.io_Unit;
  86.     readNarrator->voice.message.io_Command=CMD_READ;
  87.  
  88.         /* Send asynchronous write request to device */
  89.  
  90.     if (SendIO (writeNarrator))
  91.     {
  92.         closemouth ();
  93.         return (8);
  94.     }
  95.  
  96.         /* keep sending until says "no write in progress" */
  97.  
  98.     do
  99.         DoIO (readNarrator);
  100.     while ((readNarrator->voice.message.io_Error)!=ND_NoWrite);
  101.  
  102.         /* set parameters for speech */
  103.  
  104.     writeNarrator->sex=FEMALE;
  105.     writeNarrator->pitch=DEFPITCH;
  106.  
  107.     return (0);        /* Everything OK */
  108. }
  109.  
  110. say (string)
  111. char *string;
  112. {
  113.     (void)Translate (string,strlen (string),outputstring,MAXLEN);
  114.     writeNarrator->message.io_Data=(APTR)outputstring;
  115.     writeNarrator->message.io_Length=strlen (outputstring);
  116.     DoIO (writeNarrator);
  117. }
  118.  
  119. closemouth ()
  120. {
  121.     if (writeNarrator)
  122.     {
  123.         CloseDevice (writeNarrator);
  124.         DeleteExtIO (writeNarrator,sizeof(struct narrator_rb));
  125.     }
  126.     if (readNarrator)
  127.         DeleteExtIO (readNarrator,sizeof(struct mouth_rb));
  128.     if (writeport)
  129.         DeletePort (writeport);
  130.     if (readport)
  131.         DeletePort (readport);
  132.     if (TranslatorBase)
  133.         CloseLibrary (TranslatorBase);
  134. }
  135.